package com.ttt.adbgui.gui;

import com.ttt.adbgui.function.ReplaceComponent;
import com.ttt.adbgui.guiimp.MonkeyImp;
import com.ttt.adbgui.jcomp.JFrameComponent;
import com.ttt.adbgui.utils.JavaCMD;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.Arrays;

@Component
@Slf4j
public class GUIMonkey {

    @Autowired
    private JFrameComponent component;
    @Autowired
    private MonkeyImp monkeyImp;

    /*

    * 应用包名     多行文本输入
    * 日志级别     下啦选项-V-V-V
    * 执行间隔     数值输入
    * seed值      单行文本输入
    * 事件数量     数字输入框
    * 日志文件     单行文本输入
    * 打开日志文件  按钮
    * */
    public void monkeyGui(){

        // textPanel
        JTextPane packageName = component.getPackageName();
        JTextPane logLevel = component.getLogLevel();
        JTextPane stepDelay = component.getStepDelay();
        JTextPane seedValue = component.getSeedValue();
        JTextPane functionNum = component.getFunctionNum();
        JTextPane logPath = component.getLogPath();
        // textField
        JTextField packageNameField = component.getPackageNameField();
        JTextField logLevelField = component.getLogLevelField();
        JTextField stepDelayField = component.getStepDelayField();
        JTextField seedValueField = component.getSeedValueField();
        JTextField functionNumField = component.getFunctionNumField();
        JTextField logPathField = component.getLogPathField();
        // textArea
        JTextArea adbMonkeyTextArea = component.getAdbMonkeyTextArea();
        // 执行按钮 、 查看日志
        JButton startButton = component.getStartButton();
        JButton catLog = component.getCatLog();
        // scrollPanel
        JScrollPane jScrollPaneMonkey = component.getJScrollPaneMonkey();

        ArrayList<JComponent> jComponents = new ArrayList<>();
        jComponents.add(packageName);
        jComponents.add(logLevel);
        jComponents.add(stepDelay);
        jComponents.add(seedValue);
        jComponents.add(functionNum);
        jComponents.add(logPath);
        jComponents.add(packageNameField);
        jComponents.add(logLevelField);
        jComponents.add(stepDelayField);
        jComponents.add(seedValueField);
        jComponents.add(functionNumField);
        jComponents.add(logPathField);
        jComponents.add(adbMonkeyTextArea);
        jComponents.add(startButton);
        jComponents.add(catLog);
        jComponents.add(jScrollPaneMonkey);

        // 组件定制
        monkeyImp.starImp(jComponents);
        jComponents.remove(12);

        // add
        JDesktopPane rightDesktopPane = component.getRightDesktopPane();
        rightDesktopPane.removeAll();
        for (JComponent tmp:jComponents
             ) {
            rightDesktopPane.add(tmp);
        }
        rightDesktopPane.repaint();
    }
}
